home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / WarpOS / Source / ULP2.asm < prev    next >
Encoding:
Assembly Source File  |  2001-03-27  |  4.4 KB  |  164 lines

  1.  
  2. #    r0        volatile, may be used by function linkage
  3. #    r1        stack pointer
  4. #    r2        table of contents register
  5. #    r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  6. #    r5  .. r10    volatile, pass 3rd - 8th int args
  7. #    r11        volatile, pass static chain if language needs it
  8. #    r12        volatile, used by dyn linker, exception handling
  9. #    r13 .. r31    saved
  10.  
  11. #    f0        volatile
  12. #    f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  13. #    f5  .. f13    volatile, pass 5th - 13th float args
  14. #    f14 .. f31    saved
  15.  
  16. #    Use r22 as Color
  17. #    Use r23    as CurCnt
  18. #    Use r24    as MaxCnt (Constant value)
  19. #    Use r25    as LPixelBuf
  20. #    Use r26    as location within ColorTable32
  21. #    Use r27    as base address of ColorTable32
  22. #    Use r28    as BPP (that is, bytes per pixel)
  23.  
  24. #    r29    as RightEdge
  25. #    r30    as xtemp (integer)
  26.  
  27. #    Note that the following are constants, and independent of xtemp.
  28.  
  29. #    First the integers
  30. #    MaxCnt    in r24
  31. #    LPixelBuf in r25. It changes but need only be loaded 1 time.
  32. #    Base address of ColorTable32 in r27
  33. #    BPP in r28
  34.  
  35. #    Now the floats    (Newly defined)
  36.  
  37.  
  38. #    Zr in f15 (changes as DX is added in on each pass)
  39. #    Use f16    as value of yRel.  This is constant for each line.
  40. #    Use f17    as value that was stored in 40(r1).  It's Zi
  41. #    Use f18    as Zr.
  42. #    Use f19 as Zr2 + Zi2 = |Z2|    Only for comparing with Limit.
  43. #    Use f20    This is scratch and used shortly for 2Zi.
  44. #    Delta x    in f21
  45. #    Two    in f22
  46. #    Limit    in f23
  47. #    Use f24    as Zr2.  This is also a temporary value
  48.  
  49.  
  50.     .global    @__UseLibP2
  51.     .text
  52.     .sdreg    r2
  53.     .global    _UseLibP2
  54.     .align    4
  55. _UseLibP2:
  56.     mflr    r11
  57.     stw    r11,8(r1)    #Save return address
  58.     stwu    r1,-96(r1)      #Save stack pointer
  59.     fmr    f16,f1        #Transfer yrel from f1 to f16
  60.  
  61.     lwz    r24,_MaxCnt(r2)        #MaxCnt in r24.
  62.     lwz    r25,_LPixelBuf(r2)    #Get Location of LPixelBuf
  63.     lwz    r27,_ColorTable32(r2)    #Start of color table
  64.     lwz    r28,_BPP(r2)             #Number bytes per pixel
  65.     lfd    f25,_Factor(r2)    #Get Factor into f25
  66.     lfd    f22,_Two(r2)    #Get Two into f22 as constant
  67.     lfd    f23,_Limit(r2)    #Get Limit into f23 as constant
  68.  
  69.     li    r30,0        #xtemp = 0.
  70.  
  71. #    Find real value associated with xtemp = 0
  72.     fsub    f15,f22,f22    #f15 = f22 - f22 = 0.
  73.     lfd    f10,_XCenter(r2)#f10 = XCenter
  74.     fsub    f15,f15,f10    #xRel = xRel - XCenter
  75.     fdiv    f15,f15,f25    #Zr = xRel/Factor
  76.     lfd    f21,_DX(r2)    #Get the real value of Delta x.
  77.     lwz    r29,_RightEdge(r2)
  78.  
  79. Start:
  80.     fmr    f18,f15        #Zr -> xRel.
  81. #  The following line was moved before rather than after fmr f17,f16
  82. #  to give the fpu a break.
  83.     li    r23,1        #Initialize CurCnt = 1
  84.     fmr    f17,f16        #yRel -> Zi.
  85.     b    l3        #Check to see if to MaxCnt
  86. l2:    fmul    f24,f18,f18    #Zr2 in f24
  87.     fmul    f4,f17,f17    #Zi2 = Zi*Zi
  88.     fadd    f19,f24,f4    #Zr2 + Zi2 for |Z2|
  89.     fcmpu    cr0,f19,f23    #Compare with Limit in f23.
  90.     ble    cr0,l6
  91.  
  92. #The following section is not very time-critical as it is only reached once.
  93. #for each pixel
  94.     cmpwi    cr0,r28,2    #See if BPP < 2
  95.     blt    cr0,l8
  96. l7:
  97.     slwi    r10,r23,2    #4 times CurCnt for offset in ColorTable32
  98.     add    r26,r27,r10    #Find location of pixel color in ColorTable32
  99.     lwz    r11,0(r26)    #Get ARGB from ColorTable
  100.     stw    r11,0(r25)    #Store color in LPixelBuf
  101.     addi    r25,r25,4    #Point to next location in LPixelBuf
  102.     b    l1
  103. l8:    andi.    r3,r23,65535    #Mask Color into r3 for transfer to PlotIt
  104.     bl    _PlotIt
  105. l9:    b    l1
  106.  
  107. #Now calcuate new values for Zi and Zr.
  108. l6:
  109.     fmul    f20,f22,f17    #Find 2*Zi (Two in f22)
  110.     fsub    f10,f24,f4      #Zr2 = Zr2 - Zi2
  111.     fmul    f17,f20,f18    #Find 2*Zi*Zr (temporary Zi)
  112.  
  113.     addi    r23,r23,1       #Increment CurCnt
  114.     fadd    f18,f15,f10    #New Zr = xRel + Zr2
  115.     fadd    f17,f16,f17    #Zi = Zi + yRel
  116. l3:
  117.     cmpw    cr0,r23,r24    #See if CurCnt < MaxCnt
  118.     blt    cr0,l2        #Repeat until MaxCnt reached
  119.  
  120.     cmpwi    cr0,r28,2    #See if BPP < 2
  121.     blt    cr0,l11
  122. l10:
  123.  
  124.     lis    r12,4
  125.     addi    r12,r12,-4
  126.     add    r26,r27,r12    #Find location of pixel color
  127.     lwz    r11,0(r26)      #Get color
  128.  
  129.     stw    r11,0(r25)    #Store color in LPixelBuf
  130.     addi    r25,r25,4    #Point to next pixel in buffer
  131.     b    l1        #Was l12
  132. l11:
  133.     lis    r11,1
  134.     addi    r3,r11,-1    #ffff r3 for transfer to PlotIt
  135.     bl    _PlotIt
  136. l1:
  137.     addi    r30,r30,1       #Increment xtemp
  138.     fadd    f15,f15,f21    #Find new value of xRel.
  139.     cmpw    cr0,r30,r29    #See if to RightEdge
  140.  
  141.     blt    cr0,Start    #Repeat until row is done.
  142.     stw    r25,_LPixelBuf(r2)  #New location in long pixel buffer
  143.     addi    r1,r1,96        #Balance Stack pointer
  144.     lwz    r11,8(r1)    #Get return address
  145.     mtlr    r11
  146.     blr
  147.     .type    _UseLibP2,@function
  148.     .size    _UseLibP2,$-_UseLibP2
  149.  
  150.     .global    _MaxCnt
  151.     .global    _RightEdge
  152.     .global    _XCenter
  153.     .global    _Factor
  154.     .global    _Limit
  155.     .global    _Two
  156.     .global    _Color
  157.     .global    _LPixelBuf
  158.     .global    _ColorTable32
  159.     .global    _BPP
  160.     .global    _DX
  161.     .global    _PlotIt
  162.     .global    @__PlotIt
  163.  
  164.